//-
//- Copyright (c) Microsoft. All rights reserved.
//- Licensed under the MIT license. See LICENSE file in the project root for full license information.
//-

- var azureSignoutLink = azureSignout || '/signout/azure'
- var githubSignoutLink = githubSignout || '/signout/github?redirect=github'
- var scheme = primaryAuthenticationScheme || (config ? config.authentication.scheme : null)

mixin userTile(username, displayName, link, linkTitle, actionLink, action)
  if username
    a.btn.btn-sm.btn-muted(href=link, target='_new', title=linkTitle)= username
  if displayName
    a.btn.btn-sm.btn-muted-more(href=link, target='_new', title=linkTitle)= displayName
  if action
    a.btn.btn-sm.btn-white(href=actionLink, style='margin-left:10px')= action

mixin userGitHub
  - var actionLink = scheme === 'github' || !ossLink ? githubSignoutLink : '/link/update'
  - var action = scheme === 'github'|| !ossLink ? 'Sign Out' : 'Change'
  if hideGitHubAccount === true
    //- A few specific pages should not show the GitHub account user pane
  else
    h4 GitHub Account
    if user && user.github
      p
        if user.github.avatarUrl
          img(alt=user.github.displayName, src=user.github.avatarUrl + '&s=80', style='margin-right:10px;width:30px;height:30px', data-user=user.github.id)
        +userTile(user.github.username, user.github.displayName || user.github.username, 'https://github.com/settings/profile', 'Click to edit your public GitHub profile', actionLink, action)
    else
      if scheme === 'github'
        p
          small Sign in or create your GitHub.com account to manage your #{config && config.brand.companyName || 'corporate'} open source identity
      p
        a.btn.btn-sm.btn-primary(href='/signin/github') Sign In

mixin userAzure
  - var actionLink = scheme === 'github' ? '/link/update' : azureSignoutLink
  - var action = scheme === 'github' ? 'Change' : 'Sign Out'
  if user && user.azure
    h4 #{config && config.brand.companyName ? config.brand.companyName : 'Corporate'} Identity
    p
      +userTile(user.azure.username, user.azure.displayName, '/settings', 'View your settings', actionLink, action)
  else if scheme !== 'github'
    h4 #{config && config.brand.companyName ? config.brand.companyName : 'Corporate'} Identity
    p
      small Sign in to manage your #{config && config.brand.companyName || 'corporate'} open source identity
    p
      a.btn.btn-sm.btn-primary(href='/signin') Sign In

div.navbar.navbar-default.second-row-nav
  div.container
    div.navbar-header
      //-button.navbar-toggle.collapsed(type='button', data-toggle='collapse', data-target='.nav-collapse')
      //-button.navbar-toggle(type='button', data-toggle='collapse', data-target='.nav-collapse')
        span.sr-only Toggle navigation
        span.icon-bar
        span.icon-bar
        span.icon-bar
      //- a.navbar-brand(href='./')= page.folderMetadata.title
    //nav.collapse.navbar-collapse.nav-collapse(role='navigation')
    nav(role='navigation')
      div.container(style='margin-top:24px;margin-bottom:12px')
        div.row(style=(user && !error && ossLink) ? 'margin-left:0' : 'margin-left:-30px')
          div.col-md-6
            if scheme === 'github'
              +userGitHub
            else
              +userAzure
          div.col-md-6
            unless error
              if scheme === 'github'
                +userAzure
              else if user && user.azure && user.azure.username
                +userGitHub
